﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
//var StreetStore = new Ext.data.Store({
//    proxy: new Ext.data.HttpProxy({
//        url: '../Service/HouseDistrictService.aspx?Action=GetStreet'
//    }),
//    reader: new Ext.data.JsonReader({
//        root: 'topics',
//        totalProperty: 'totalCount',
//        id: 'Name',
//        fields: ['Name', 'Id']
//    }),
//    remoteStore: true
//});
//StreetStore.load();

//var CommunityStore = new Ext.data.Store({
//    proxy: new Ext.data.HttpProxy({
//        url: '../Service/HouseDistrictService.aspx?Action=GetCommunity'
//    }),
//    reader: new Ext.data.JsonReader({
//        root: 'topics',
//        totalProperty: 'totalCount',
//        id: 'Name',
//        fields: ['Name', 'Id']
//    }),
//    remoteStore: true
//});
//CommunityStore.load();

//var PoliceStationStore = new Ext.data.Store({
//    proxy: new Ext.data.HttpProxy({
//        url: '../Service/HouseDistrictService.aspx?Action=GetPoliceStation'
//    }),
//    reader: new Ext.data.JsonReader({
//        root: 'topics',
//        totalProperty: 'totalCount',
//        id: 'Name',
//        fields: ['Name', 'Id']
//    }),
//    remoteStore: true
//});
//PoliceStationStore.load();

FantastPlatform.UI.HouseDistrictForm = function (config) {
    Ext.apply(this, config);
//    var StreetComboBox = new Ext.form.ComboBox({
//        fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;所属街道',
//        name: 'Street',
//        hiddenName: 'Street',
//        store: StreetStore,
//        displayField: 'Name',
//        mode: 'remote',
//        valueField: 'Id',
//        allowBlank: false,
//        editable: false,
//        triggerAction: 'all',
//        emptyText: '选择所属街道',
//        width: 130
//    }); 
    var StreetComboBox = new FantastPlatform.CaseManagement.SearchField({
        fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;所属街道',
        name: 'StreetName',
        hiddenName: 'StreetId',
        parentField:'Community',
        valueField: 'Id',
        url: "../Service/HouseDistrictService.aspx?Action=GetStreet",
        readOnly: true,
        allowBlank: false,
        blankText: '所属街道不能为空',
        width: 130
    });
//    var PoliceStationComboBox = new Ext.form.ComboBox({
//        fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;所属派出所',
//        name: 'PoliceStation',
//        hiddenName: 'PoliceStation',
//        store: PoliceStationStore,
//        displayField: 'Name',
//        mode: 'remote',
//        valueField: 'Id',
//        allowBlank: false,
//        editable: false,
//        triggerAction: 'all',
//        emptyText: '选择所属派出所',
//        width: 130
//    });
    var PoliceStationComboBox = new FantastPlatform.CaseManagement.SearchField({
        fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;所属派出所',
        name: 'PoliceStationName',
        hiddenName: 'PoliceStation',
        valueField: 'Id',
        url: "../Service/HouseDistrictService.aspx?Action=GetPoliceStation",
        readOnly: true,
        allowBlank: false,
        blankText: '选择所属派出所',
        width: 130
    });
    var CommunityComboBox = new FantastPlatform.CaseManagement.SearchField({
        fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;所属责任区',
        name: 'CommunityName',
        hiddenName: 'Community',
        valueField: 'Id',
        url: "../Service/HouseDistrictService.aspx?Action=GetCommunity",
        readOnly: true,
        allowBlank: false,
        parentField: 'PoliceStation',
        blankText: '选择所属责任区',
        width: 130
    });
//    PoliceStationComboBox.on('select', function () {
//        var Id = PoliceStationComboBox.getValue();
//        var url = '../Service/HouseDistrictService.aspx?Action=GetCommunity';
//        CommunityStore.removeAll();
//        CommunityStore.proxy.conn = { method: 'post', url: url };
//        CommunityStore.reload({ params: { Id: Id} });
//    });
//    var CommunityComboBox = new FantastPlatform.UI.AutoComplateComboBox({
//        fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;所属责任区',
//        name: 'Community',
//        hiddenName: 'Community',
//        store: CommunityStore,
//        displayField: 'Name',
//        mode: 'remote',
//        valueField: 'Id',
//        allowBlank: false,
//        editable: false,
//        triggerAction: 'all',
//        emptyText: '选择所属责任区',
//        width: 130
//    });
//    CommunityComboBox.on('select', function () {
//        var Id = CommunityComboBox.getValue();
//        var url = '../Service/HouseDistrictService.aspx?Action=GetStreet';
//        StreetStore.removeAll();
//        StreetStore.proxy.conn = { method: 'post', url: url };
//        StreetStore.reload({ params: { Id: Id} });
//    });
    this.items = [{
        layout: 'column',
        border: false,
        labelSeparator: '：',
        items: [{
            columnWidth: .5,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '名称',
                name: 'Name',
                allowBlank: false,
                blankText: "名称不能为空",
                anchor: '98%'
            })]
        }, {
            columnWidth: .5,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '门卫物管',
                name: 'Concierge',
                anchor: '98%'
            })]
        }, {
            columnWidth: .5,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '联系号码',
                name: 'Phone',
                anchor: '98%'
            })]
        }, {
            columnWidth: .5,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '责任民警',
                emptyText: '系统自动生成',
                name: 'PoliceMan',
                hiddenName: 'PoliceMan',
                displayField: 'Name',
                mode: 'remote',
                valueField: 'Id',
                triggerAction: 'all',
                readOnly: true,
                anchor: '98%'
            })]
        }
//        , {
//            columnWidth: .5,
//            border: false,
//            layout: 'form',
//            items: [new Ext.form.TextField({
//                fieldLabel: '经度',
//                name: 'longitude',
//                allowBlank: false,
//                blankText: "经度不能为空",
//                anchor: '98%'
//            })]
//        }, {
//            columnWidth: .5,
//            border: false,
//            layout: 'form',
//            items: [new Ext.form.TextField({
//                fieldLabel: '纬度',
//                name: 'latitude',
//                allowBlank: false,
//                blankText: "纬度不能为空",
//                anchor: '98%'
//            })]
//        }
        , {
            columnWidth: .5,
            border: false,
            layout: 'form',
            items: [PoliceStationComboBox]
        },
         {
             columnWidth: .5,
             border: false,
             layout: 'form',
             items: [CommunityComboBox]
         }, {
             columnWidth: .5,
             border: false,
             layout: 'form',
             items: [StreetComboBox]
         }, {
             columnWidth: .5,
             border: false,
             layout: 'form',
             items: [new Ext.form.TextField({
                 fieldLabel: '附/号',
                 name: 'Number',
                 anchor: '98%'
             })]
         }, {
             columnWidth: 1,
             border: false,
             layout: 'form',
             items: [new Ext.form.TextField({
                 fieldLabel: '描述',
                 name: 'Description',
                 height: 50,
                 anchor: '98%'
             })]
         }, {
             columnWidth: .5,
             border: false,
             layout: 'form',
             items: [new Ext.form.Hidden({
                 fieldLabel: '创建时间',
                 name: 'CreateDate',
                 anchor: '98%'
             })]
         }]
    }];

    FantastPlatform.UI.HouseDistrictForm.superclass.constructor.call(this, {
        bodyStyle: 'padding:5px',
        collapsible: true,
        labelAlign: 'right',
        autoScroll: true,
        border: false
    });
};

Ext.extend(FantastPlatform.UI.HouseDistrictForm, Ext.form.FormPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.HouseDistrictForm.superclass.onRender.call(this, ct, position);
        if (this.HouseDistrictId && this.HouseDistrictId != 0) {
            this.add(new Ext.form.Hidden({ name: 'Id', value: this.HouseDistrictId }));
            this.form.load({
                url: '../Service/HouseDistrictService.aspx?Action=Get',
                params: { id: this.HouseDistrictId },
                waitMsg: '正在读取数据...',
                waitTitle: '请稍后...',
                failure: function (form, action) {
                    if (action.failureType != 'client') {
                        showErrorMessage('操作失败', action.result.message, '');
                    }
                }
            });
        }
    }
});

